package cn.xgj.sfzy.service.impl;

import cn.xgj.sfzy.entity.*;
import cn.xgj.sfzy.mapper.AppointmentMapper;
import cn.xgj.sfzy.mapper.ConsultMapper;
import cn.xgj.sfzy.mapper.UserAssessmentMapper;
import cn.xgj.sfzy.service.AppointmentService;
import cn.xgj.sfzy.service.UserAssessmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName UserAssessmentServiceImpl
 * @Description TODO
 * @Author furuyue
 * @Date 2024年10月24日 11:37
 * @Version 1.0
 */

@Service
public class UserAssessmentServiceImpl implements UserAssessmentService {

    @Autowired
    private UserAssessmentMapper userAssessmentMapper;

    @Autowired
    private AppointmentMapper appointmentMapper;

    @Autowired
    private ConsultMapper consultMapper;

    public int remove(Integer id) {
        return userAssessmentMapper.delete(id);
    }

    public List<UserAssessment> findAll(UserAssessment UserAssessment) {
        return userAssessmentMapper.find(UserAssessment);
    }

    public PageInfo<UserAssessment> findByPage(Integer pageNum, Integer pageSize, UserAssessment userAssessment) {
        PageHelper.startPage(pageNum,pageSize);
        List<UserAssessment> list = userAssessmentMapper.find(userAssessment);
        PageInfo<UserAssessment> info = new PageInfo<UserAssessment>(list);
        return info;
    }

    @Override
    public List<UserAssessment> findByAppointmentId(Long appointmentId) {


            List<UserAssessment> list = userAssessmentMapper.findByAppointmentId(appointmentId);
            for(UserAssessment a :list){
                Long appointmentId1= a.getAppointmentId();
                Appointment appointment = appointmentMapper.findById(appointmentId1.intValue());
                Long consultId = appointment.getConsultId();
                Consult consult = consultMapper.selectById(consultId.intValue());
                appointment.setConsult(consult);
                a.setAppointment(appointment);
            }
            return list;
    }

    @Override
    public int add(UserAssessment userAssessment) {
        return userAssessmentMapper.add(userAssessment);
    }

    @Override
    public int edit(UserAssessment userAssessment) {
        return userAssessmentMapper.update(userAssessment);
    }
}
